//
//  RecordAlertView.m
//  cascade-realm
//
//  Created by QSC on 3/6/24.
//

#import "RecordAlertView.h"

@interface RecordAlertView()
@property (nonatomic,strong)UIImageView * centerImageV;
@property (nonatomic,strong)UIImageView * micImageV;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIImageView *bottomImageV;

@end
@implementation RecordAlertView

+ (RecordAlertView *)show{
    
    RecordAlertView * view = [RecordAlertView new];
    view.frame = [UIScreen mainScreen].bounds;
    
    [[UIApplication sharedApplication].keyWindow addSubview:view];
    
    return view;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        self.isSend = YES;
        UIImageView * centerImageV = [[UIImageView alloc] initWithImage:Img(@"reocrd1")];
        self.centerImageV = centerImageV;
        [self addSubview:centerImageV];
        [centerImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
        
        NSMutableArray * imgs = [NSMutableArray array];
        for (int i = 0 ; i < 7; i++) {
            NSString *img = [NSString stringWithFormat:@"voice%d",i];
            [imgs addObject:Img(img)];
        }
        
        centerImageV.animationImages = imgs;
        centerImageV.animationDuration = 1.5;
        [centerImageV startAnimating];

        
    
        
        
        
        UIImageView * bottomImgV = [[UIImageView alloc] initWithImage:Img(@"record_bottom")];
        [self addSubview:bottomImgV];
        [bottomImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.mas_equalTo(140 + kBottomSafeHeight);
        }];
        self.bottomImageV = bottomImgV;
        
        UILabel * titleLabel = [UILabel LabelWithFont:BoldFont(16) color:[UIColor whiteColor] text:@"Release Send"];
        self.titleLabel = titleLabel;
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.bottom.equalTo(bottomImgV.mas_top).offset(-28);
        }];
        
        
        UIImageView * micImageV = [[UIImageView alloc] initWithImage:Img(@"recordmic1")];
        self.micImageV = micImageV;
        [self addSubview:micImageV];
        [micImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.size.mas_equalTo(62);
            make.top.equalTo(bottomImgV).offset(44);
        }];
        
    }
    return  self;
}


- (void)changeMode:(CGFloat)offset{
    
    if (offset < self.bottomImageV.top) {
        self.titleLabel.text = @"Release Cancel";
        self.micImageV.image = Img(@"recordmic2");
        self.centerImageV.image = Img(@"record2");
       
        self.isSend = NO;
        [self.centerImageV stopAnimating];
    }else{
        self.titleLabel.text = @"Release Send";
        self.micImageV.image = Img(@"recordmic1");
        self.centerImageV.image = Img(@"reocrd1");
      
        [self.centerImageV startAnimating];
        self.isSend = YES;
    }
    
}

@end
